<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天气案例</title>
    <script src="../commonjs/vue.js"></script>
</head>
<body>
    <div id="root">
        <span>今天天气真{{info}}<br/><br/></span>
        <button @click="changeWeather">切换天气</button>
    </div>
    <script>
        Vue.config.productionTip = false;//关闭开发提示
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true
            },
            computed:{
                info(){
                    return this.isHot ? '炎热' : '寒冷'
                }
            },
            methods:{
                changeWeather(){
                    this.isHot = !this.isHot
                }
            },
            //属性监视第一种写法
/*            watch:{
                isHot:{
                    immediate:true, //立即执行，不用等值发生改变
                    //isHot发生改变时调用
                    handler(newValue,oldValue){
                        console.log("isHot被修改了！",newValue,oldValue)
                    }
                }
            }*/
        })
        //属性监视第二种写法
        vm.$watch('isHot',{
            immediate:true,
            handler(newValue,oldValue){
                console.log("isHot被修改了！",newValue,oldValue)
            }
        })
    </script>
</body>
</html>